package com.tql.mall.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.tql.mall.mapper.CommentInfoMapper;
import com.tql.mall.model.comment.CommentInfo;
import com.tql.mall.model.comment.CommentInfoVo;
import com.tql.mall.model.customer.Customer;
import com.tql.mall.model.order.OrderInfo;
import com.tql.mall.order.client.OrderFeignClient;
import com.tql.mall.service.CommentInfoService;
import com.tql.mall.user.client.UserFeignClient;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class CommentInfoServiceImpl extends ServiceImpl<CommentInfoMapper, CommentInfo> implements CommentInfoService {



    @Autowired
    private UserFeignClient userFeignClient;

    @Autowired
    private OrderFeignClient orderFeignClient;


    @Override
    public void addComment(CommentInfoVo commentInfoVo) {
        CommentInfo commentInfo = new CommentInfo();
        BeanUtils.copyProperties(commentInfoVo,commentInfo);
        //获取店铺id(根据订单)
        OrderInfo orderInfo = orderFeignClient.getOrderInfo(commentInfoVo.getOrderId());
        System.out.println(orderInfo.toString());
        commentInfo.setShopId(orderInfo.getShopId());
        //获取顾客头像和昵称
        Customer customer = userFeignClient.getCustomer(commentInfoVo.getCustomerId());
        commentInfo.setHeadImg(customer.getAvatar());
        commentInfo.setNickName(customer.getNickName());

        baseMapper.insert(commentInfo);
    }
}
